/*{
author=pk2.2（风铃等）
version=2.0
date=2023/03/19
}*/

/***
可以设定兵役政策.
***/

// ## 2023/11/03 # 铃 # 创建。 ##


namespace 兵役政策
{
    const int KEY = pk::hash("兵役政策");

    class Main
    {


        pk::building @building_;
        pk::force @force;
        pk::person @taishu;
        pk::person @farmer;
        int building_id = -1;
        int province_id = 0;
        float deserter;

        Main()
        {
            pk::menu_item item;
            item.menu = 101;
            item.pos = 8;
            item.shortcut = "z";
            item.init = pk::building_menu_item_init_t(init);
            item.is_visible = pk::menu_item_is_visible_t(isVisible);
            item.is_enabled = pk::menu_item_is_enabled_t(isEnabled);
            item.get_text = pk::menu_item_get_text_t(getText);
            item.get_desc = pk::menu_item_get_desc_t(getDesc);
            item.handler = pk::menu_item_handler_t(handler);
            pk::add_menu_item(item);
        }

        void init(pk::building @building)
        {
            @building_ = @building;
            building_id = building.get_id();
            @force = pk::get_force(building.get_force_id());
            @taishu = pk::get_person(pk::get_taishu_id(building));
        }

        bool isVisible()
        {
            if (building_id == -1 or building_id >= 据点_末)
                return false;
            return true;
        }

        bool isEnabled()
        {
            // if (pk::is_absent(taishu) or pk::is_unitize(taishu))
            //     return false;
            return true;
        }

        string getText()
        {
            return pk::encode("兵役政策");
        }

        string getDesc()
        {
            // if (taishu is null)
            //     return pk::encode("无太守无法执行.");
            return pk::encode(pk::format("兵役政策设定{} ", ""));
        }

        bool handler()
        {
            auto building_p = ch::get_baseIA(building_id);
            string title;
            string policy_;
            int policy;

            array<string> select_data;
            array<string> select_data2;

            title = pk::encode("请选择本城的兵役政策");
            select_data = {
                pk::encode("强征兵役(兵役转换率↑↑↑,人口增速↓↓,治安↓↓)"),
                pk::encode("积极动员(兵役转换率↑↑,人口增速↓)"),
                pk::encode("均衡政策(兵役转换率默认,人口增速不变)"),
                pk::encode("安民政策(兵役转换率↓↓,人口增速↑)"),
                pk::encode("休养生息(兵役转换率=0,人口增速↑↑)")};

            select_data2 = {
                "强征", "积极", "均衡", "安民", "休养"};

            policy = pk::choose(title, select_data);
            building_p.building_policy = policy;
            policy_ = select_data2[policy];

            pk::message_box(pk::encode(pk::format("兵役政策设定为\x1b[1x{}.", policy_)));
            人口系统::main.func_pop_calc(false);

            return true;
        }
    }

    Main main;
}